//
//  KuaiDiViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/30.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "KuaiDiViewController.h"

@interface KuaiDiViewController ()<UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate>{
    NSMutableArray *array;
    UIPickerView *pickerViews;
    NSString *kd;
}
@property (weak, nonatomic) IBOutlet UILabel *labToAddress;
@property (weak, nonatomic) IBOutlet UITextField *labHouse;
@property (weak, nonatomic) IBOutlet UILabel *labGoAddress;
@property (weak, nonatomic) IBOutlet UITextField *labDetText;
@property (weak, nonatomic) IBOutlet UITextField *labWeight;
@property (weak, nonatomic) IBOutlet UITextView *labBeiZu;
@property (weak, nonatomic) IBOutlet UIButton *BtnKDCompany;

@end

@implementation KuaiDiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"快递"];
    array = [NSMutableArray array];
    _labBeiZu.delegate = self;
    _labBeiZu.layer.borderWidth = 1.0;
    _labBeiZu.layer.cornerRadius = 5.0;
    _labBeiZu.layer.borderColor = COLOR_RGB(242, 242, 242, 242).CGColor;
    
    [self loadKD];
    
}
//
- (IBAction)clickSelKD:(UIButton *)sender {
    [UIView animateWithDuration:0.5 animations:^{
        pickerViews = [[UIPickerView alloc] initWithFrame:CGRectMake(0, ScreenHeight-200, ScreenWidth, 200)];
        pickerViews.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        pickerViews.delegate = self;
        pickerViews.dataSource = self;
        [pickerViews selectRow:0 inComponent:0 animated:YES];
        [self.view addSubview:pickerViews];
    }];
    
    
}
#pragma -mark UIPickerViewDataSource
//返回多少列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
//返回多少行
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return array.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return array[row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"%@",array[row]);
    kd = array[row];
    [_BtnKDCompany setTitle:kd forState:UIControlStateNormal];
}

#pragma -mark UITextViewDelegate
-(void)textViewDidBeginEditing:(UITextView *)textView{
    
}

//返回快递公司
- (void)loadKD{
    NSString *url = [NSString stringWithFormat:@"%@/App/Expressage/index",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *arr = [responseObject objectForKey:@"result"];
        for (NSDictionary *dic in arr) {
            NSString *expressname = [dic objectForKey:@"expressname"];
            [array addObject:expressname];
        }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

- (IBAction)clickTel:(id)sender {
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:kd forKey:@"expresscompany"];
    [parmas setObject:@"重庆九龙坡区杨家坪盛仁汇大厦" forKey:@"upaddress"];
    [parmas setObject:@"2009" forKey:@"housenumber"];
    [parmas setObject:@"重庆市" forKey:@"goprovince"];
    [parmas setObject:@"杨家坪" forKey:@"gocity"];
    [parmas setObject:@"黄桷坪正街" forKey:@"gozone"];
    [parmas setObject:@"115-1" forKey:@"goaddress"];
    [parmas setObject:@"10" forKey:@"weight"];
    [parmas setObject:@"帅枫" forKey:@"ordername"];
    [parmas setObject:_lat forKey:@"latitude"];
    [parmas setObject:_lng forKey:@"longitude"];
    
    NSLog(@"parmas:%@",parmas);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *url = [NSString stringWithFormat:@"%@/App/Expressage/upload",urlHead];
    [manager POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSLog(@"msg:%@",[responseObject objectForKey:@"mssage"]);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    
    [UIView animateWithDuration:0.5 animations:^{
        [pickerViews removeFromSuperview];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
